/*
 * BasicQueue.cpp
 *
 *  Created on: Oct 29, 2012
 *  Author: Trenton Nall
 *  Assignment: Homework 7
 */

#include "BasicQueue.h"

/**************************************************************
 Function enqueue
 PURPOSE: inserts an item in the queue
 PARAMETERS: item - item to be inserted in the queue
 CALLED BY: testQuestion1Queue
 SIDE EFFECTS: Adds an item to the internal queue
 ***************************************************************/
void BasicQueue::enqueue(int item) {
	storage.push_back(item);
}

/**************************************************************
 Function dequeue
 PURPOSE: removes an item from the queue
 CALLED BY: testQuestion1Queue
 SIDE EFFECTS: Returns an item removed from the queue.
 ***************************************************************/
int BasicQueue::dequeue() {
	// throw an exception if someone attempts
	// to dequeue an item from an empty queue
	if (size() < 1) {
		throw -1;
	}

	// get the first item in the queue and erase
	// it from internal storage
	int frontItem = storage.front();
	storage.erase(storage.begin(), storage.begin() + 1);

	return frontItem;
}

/**************************************************************
 Function empty
 PURPOSE: empties all items from the queue
 PARAMETERS: none
 CALLED BY: testQuestion1Queue
 SIDE EFFECTS: Removes all items from internal storage.
 ***************************************************************/
void BasicQueue::empty() {
	// clear the internal storage facility
	storage.clear();
}

/**************************************************************
 Function size
 PURPOSE: gets the # of items currently stored in the queue
 PARAMETERS: none
 CALLED BY: testQuestion1Queue
 SIDE EFFECTS: This function changes no global variables or
 parameters.
 ***************************************************************/
int BasicQueue::size() {
	// get the # of items stored in internal storage
	return storage.size();
}

/**************************************************************
 Function BasicQueue
 PURPOSE: constructs internal storage for queue
 PARAMETERS: none
 CALLED BY: testQuestion1Queue
 SIDE EFFECTS: This function creates the internal storage of the queue.
 ***************************************************************/
BasicQueue::BasicQueue() :
	storage() {
}

/**************************************************************
 Function ~BasicQueue
 PURPOSE: clears contents of queue internal storage on destuction of the queue
 PARAMETERS: none
 CALLED BY: testQuestion1Queue
 SIDE EFFECTS: Clears internal storage
 ***************************************************************/
BasicQueue::~BasicQueue() {
	storage.clear();
}
